package com.ruoyi.back.controller

import com.ruoyi.app.common.Data
import com.ruoyi.app.common.PageData
import com.ruoyi.back.domain.dto.BackUserDto
import com.ruoyi.back.domain.vo.BackUserVo
import com.ruoyi.back.service.BackUserService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("system/backUser")
@Api(tags = ["后台用户管理接口"])
class BackUserController {

    @Autowired
    private lateinit var backUserService: BackUserService

    @ApiOperation("保存或者编辑用户")
    @PostMapping("save")
    fun saveBackUser(@RequestBody backUserDto: BackUserDto): Data<Boolean> =
        backUserService.saveBackUser(backUserDto)

    @ApiOperation("获取用户列表")
    @GetMapping("list")
    @ApiImplicitParams(
        ApiImplicitParam(name = "searchParam", value = "搜索参数",  required = false)
    )
    fun backUserPage(searchParam: String?): PageData<BackUserVo> =
        backUserService.backUserPage(searchParam)

    @ApiOperation("批量移除用户")
    @ApiImplicitParams(
        ApiImplicitParam(name = "userIds", value = "用户id 多个使用逗号", type = "path", required = true)
    )
    @PostMapping("remove/{userIds}")
    fun removeUser(@PathVariable userIds: String): Data<Boolean> =
        backUserService.removeUser(userIds)
}